﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MyLesson.ascx.cs" Inherits="TeachingAffairsManagementSystem.UserControl.RightContent.Teacher.MyLesson" %>
<%@ Register Src="~/WebControl/AlertBox.ascx" TagPrefix="uc1" TagName="AlertBox" %>

<uc1:AlertBox runat="server" ID="Alert"/>
<div id="gridview">
    <div class="form-group">
        <asp:GridView ID="GVMyLesson" runat="server" DataSourceID="DSMyLesson" AutoGenerateColumns="False" DataKeyNames="l_id,teacher_t_id" AllowPaging="True" AllowSorting="True" CssClass="table table-bordered table-hover" OnRowCommand="GVLesson_RowCommand">
            <Columns>
                <asp:BoundField DataField="l_id" HeaderText="课程ID" ReadOnly="True" SortExpression="l_id"/>
                <asp:BoundField DataField="teacher_t_id" HeaderText="teacher_t_id" ReadOnly="True" SortExpression="teacher_t_id" Visible="False"/>
                <asp:BoundField DataField="name" HeaderText="课程名称" SortExpression="name" ReadOnly="True"/>
                <asp:TemplateField HeaderText="课程信息" SortExpression="info">
                    <EditItemTemplate>
                        <asp:TextBox CssClass="form-control" ID="TextBox1" runat="server" Text='<%# Bind("info") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label2" runat="server" Text='<%# Bind("info") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="已完成" SortExpression="finished">
                    <EditItemTemplate>
                        <asp:DropDownList CssClass="form-control" ID="DropDownList1" runat="server" SelectedValue='<%# Bind("finished") %>'>
                            <asp:ListItem>是</asp:ListItem>
                            <asp:ListItem>否</asp:ListItem>
                        </asp:DropDownList>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("finished") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="create_time" HeaderText="创建时间" SortExpression="create_time" ReadOnly="True"/>
                <asp:ButtonField CommandName="LookUpMyStudent" Text="查看选课学生"/>
                <asp:TemplateField ShowHeader="False">
                    <EditItemTemplate>
                        <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update" Text="更新"></asp:LinkButton>
                        &nbsp;
                        <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Delete" Text="删除"></asp:LinkButton>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit" Text="编辑"></asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
    </div>
</div>

<div id="insert">
    <div class="form-group">
        <table class="table table-bordered table-hover">
            <tr>
                <td>课程名称</td>
                <td>课程信息</td>
                <td>&nbsp;</td>
            </tr>
            <tr>
                <td>
                    <asp:TextBox CssClass="form-control" ID="TBName" runat="server" MaxLength="45"></asp:TextBox>
                </td>

                <td>
                    <asp:TextBox CssClass="form-control" ID="TBInfo" runat="server" MaxLength="45" TextMode="Email"></asp:TextBox>
                </td>
                <td>
                    <asp:Button CssClass="btn btn-default" ID="BtnInsert" runat="server" Text="新建课程" OnClick="BtnInsert_Click"/>
                </td>
            </tr>
        </table>
    </div>
</div>


<asp:SqlDataSource ID="DSMyLesson" runat="server" ConnectionString="<%$ ConnectionStrings:sitedbConnectionString %>"
                   DeleteCommand="DELETE FROM lesson WHERE l_id = ? AND teacher_t_id = ?"
                   InsertCommand="INSERT INTO lesson (teacher_t_id, name, info) VALUES (?, ?, ?)" ProviderName="<%$ ConnectionStrings:sitedbConnectionString.ProviderName %>"
                   SelectCommand="SELECT * FROM lesson WHERE teacher_t_id = ?"
                   UpdateCommand="UPDATE lesson SET info = ?, finished = ? WHERE l_id = ? AND teacher_t_id = ?">
    <DeleteParameters>
        <asp:Parameter Name="l_id" Type="Int32"/>
        <asp:Parameter Name="teacher_t_id" Type="Int32"/>
    </DeleteParameters>
    <InsertParameters>
        <asp:Parameter Name="teacher_t_id" Type="Int32"/>
        <asp:Parameter Name="name" Type="String"/>
        <asp:Parameter Name="info" Type="String"/>
    </InsertParameters>
    <SelectParameters>
        <asp:SessionParameter Name="teacher_t_id" SessionField="id" Type="Int32"/>
    </SelectParameters>
    <UpdateParameters>
        <asp:Parameter Name="info" Type="String"/>
        <asp:Parameter Name="finished" Type="String"/>
        <asp:Parameter Name="l_id" Type="Int32"/>
        <asp:Parameter Name="teacher_t_id" Type="Int32"/>
    </UpdateParameters>
</asp:SqlDataSource>